import { Component, OnInit } from '@angular/core';
import { MerchanthistoryService } from 'src/app/service/merchanthistory.service';
import { MerchantService } from 'src/app/service/merchant.service';
import { ActivatedRoute } from '@angular/router';
import { RoleRight } from 'src/kalend';

@Component({
  selector: 'app-settlementrecords',
  templateUrl: './settlementrecords.component.html',
  styleUrls: ['./settlementrecords.component.scss'],
  providers: [MerchanthistoryService, MerchantService]
})
export class SettlementrecordsComponent implements OnInit {
  isadmin = RoleRight.getisRole(null, '系统管理员');
  mid: any;
  uid: any;
  paystatus = 'all';
  pageIndex = 1;
  pageSize = 15;
  footTotal: any;
  total = 1;
  dataSet = [];
  loading = true;
  isOkLoading = false;
  isVisible = false;
  starttime: any;
  endtime: any;
  isvisable = true;
  statuslist: Array<any> = [];
  paystatuslist = [{ key: 'all', value: '全部' }, { key: 0, value: '未支付' }, { key: 1, value: '支付成功' }, { key: 2, value: '已关闭' }, { key: 3, value: '已撤销' }, { key: 4, value: '支付中' }, { key: 9, value: '支付失败' }];
  constructor(private service: MerchanthistoryService, private merchservice: MerchantService, private ar: ActivatedRoute) {
    this.mid = this.ar.snapshot.params.id;
    if (this.mid || this.uid) {
      this.isvisable = false;
    }
  }
  ngOnInit() {
    this.searchData();
    this.merchservice.queryall().then((res) => {
      this.statuslist = res.map((item) => {
        return {
          key: item._id,
          value: item.name
        };
      });
    })
  }

  searchData(reset: boolean = false): void {
    this.loading = true;
    this.service.query({
      offset: this.pageIndex,
      limit: this.pageSize,
      mid: this.mid,
      starttime: this.starttime,
      endtime: this.endtime
    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows;
      this.footTotal = res.footTotal; // 如: 共计 1200 元，酒币 2000 个，餐币 150 个
    });
  }

}
